Conditions | 1 |
Paths | 1 |
Total Lines | 138 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | module.exports = function(GedcomX){ |
||
2 | |||
3 | var utils = require('../utils'); |
||
4 | |||
5 | /** |
||
6 | * Information about the contents of a collection. |
||
7 | * |
||
8 | * @see {@link https://github.com/FamilySearch/gedcomx-record/blob/master/specifications/record-specification.md#collection-content|GEDCOM X Records Spec} |
||
9 | * |
||
10 | * @class CollectionContent |
||
11 | * @extends ExtensibleData |
||
12 | * @param {Object} [json] |
||
13 | */ |
||
14 | var CollectionContent = function(json){ |
||
15 | |||
16 | // Protect against forgetting the new keyword when calling the constructor |
||
17 | if(!(this instanceof CollectionContent)){ |
||
18 | return new CollectionContent(json); |
||
19 | } |
||
20 | |||
21 | // If the given object is already an instance then just return it. DON'T copy it. |
||
22 | if(CollectionContent.isInstance(json)){ |
||
23 | return json; |
||
24 | } |
||
25 | |||
26 | this.init(json); |
||
|
|||
27 | }; |
||
28 | |||
29 | CollectionContent.prototype = Object.create(GedcomX.ExtensibleData.prototype); |
||
30 | |||
31 | CollectionContent._gedxClass = CollectionContent.prototype._gedxClass = 'GedcomX.CollectionContent'; |
||
32 | |||
33 | CollectionContent.jsonProps = [ |
||
34 | 'resourceType', |
||
35 | 'count', |
||
36 | 'completeness' |
||
37 | ]; |
||
38 | |||
39 | /** |
||
40 | * Check whether the given object is an instance of this class. |
||
41 | * |
||
42 | * @param {Object} obj |
||
43 | * @returns {Boolean} |
||
44 | */ |
||
45 | CollectionContent.isInstance = function(obj){ |
||
46 | return utils.isInstance(obj, this._gedxClass); |
||
47 | }; |
||
48 | |||
49 | /** |
||
50 | * Initialize from JSON |
||
51 | * |
||
52 | * @param {Object} |
||
53 | * @return {CollectionContent} this |
||
54 | */ |
||
55 | CollectionContent.prototype.init = function(json){ |
||
56 | |||
57 | GedcomX.ExtensibleData.prototype.init.call(this, json); |
||
58 | |||
59 | if(json){ |
||
60 | this.setResourceType(json.resourceType); |
||
61 | this.setCount(json.count); |
||
62 | this.setCompleteness(json.completeness); |
||
63 | } |
||
64 | return this; |
||
65 | }; |
||
66 | |||
67 | /** |
||
68 | * Set the resource type |
||
69 | * |
||
70 | * @param {String} resourceType |
||
71 | * @return {CollectionContent} this |
||
72 | */ |
||
73 | CollectionContent.prototype.setResourceType = function(resourceType){ |
||
74 | this.resourceType = resourceType; |
||
75 | return this; |
||
76 | }; |
||
77 | |||
78 | /** |
||
79 | * Get the resource type |
||
80 | * |
||
81 | * @return {String} resourceType |
||
82 | */ |
||
83 | CollectionContent.prototype.getResourceType = function(){ |
||
84 | return this.resourceType; |
||
85 | }; |
||
86 | |||
87 | /** |
||
88 | * Set the count |
||
89 | * |
||
90 | * @param {Integer} count |
||
91 | * @return {CollectionContent} this |
||
92 | */ |
||
93 | CollectionContent.prototype.setCount = function(count){ |
||
94 | this.count = count; |
||
95 | return this; |
||
96 | }; |
||
97 | |||
98 | /** |
||
99 | * Get the count |
||
100 | * |
||
101 | * @return {Integer} |
||
102 | */ |
||
103 | CollectionContent.prototype.getCount = function(){ |
||
104 | return this.count; |
||
105 | }; |
||
106 | |||
107 | /** |
||
108 | * Set the completeness |
||
109 | * |
||
110 | * @param {Number} completeness A number between 0 and 1 |
||
111 | * @return {CollectionContent} |
||
112 | */ |
||
113 | CollectionContent.prototype.setCompleteness = function(completeness){ |
||
114 | this.completeness = completeness; |
||
115 | return this; |
||
116 | }; |
||
117 | |||
118 | /** |
||
119 | * Get the completeness |
||
120 | * |
||
121 | * @return {Number} completeness |
||
122 | */ |
||
123 | CollectionContent.prototype.getCompleteness = function(){ |
||
124 | return this.completeness; |
||
125 | }; |
||
126 | |||
127 | /** |
||
128 | * Export the object as JSON |
||
129 | * |
||
130 | * @return {Object} JSON object |
||
131 | */ |
||
132 | CollectionContent.prototype.toJSON = function(){ |
||
133 | return this._toJSON(GedcomX.ExtensibleData, CollectionContent.jsonProps); |
||
134 | }; |
||
135 | |||
136 | GedcomX.CollectionContent = CollectionContent; |
||
137 | |||
138 | }; |